package torres.fileIO;

import java.util.ArrayList;

public class ClassContainer extends PropertyContainer {
	
	private String name;
	private ArrayList<PropertyContainer> properties;
	
	public ClassContainer(String name) {	
		this.name = name;
		properties = new ArrayList<PropertyContainer>();
	}
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public void addProperty(PropertyContainer property) {
		//System.out.println(property.getName());
		properties.add(property);
	}
	
	public PropertyContainer getProperty(String name) {
		
		for(PropertyContainer property : properties) {
			if (property.getName().equals(name))
				return property;
		}
		return null;
		
	}
	
	public PropertyContainer getProperty(String name, int i) {
		
		int j=0;
		if(i>=0) {
			for(PropertyContainer property : properties) {
				if (property.getName().equals(name))
					j++;
				if(j-1==i)
					return property;
			}
		}
		return null;
		
	}
	
	public String toString() {
		String outputString = new String();
		outputString += "<"+name +">\n";
		for(PropertyContainer property: properties) {
			
			outputString += property.toString();
			
		}
		outputString += "</"+name+">\n";
		
		return outputString;
	}
	
}
